package com.csthink.mr.outputformat;

import org.apache.hadoop.mapreduce.lib.db.DBWritable;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author <a href="mailto:csthink@icloud.com">Mars</a>
 * @since 2024-04-15 19:31
 */
public class Account implements DBWritable {

    private String id;

    private String name;

    private String email;

    private Integer isSetup;

    private Long accountOptions;

    public Account() {
    }

    public Account(String id, String name, String email, Integer isSetup, Long accountOptions) {
        this.id = id;
        this.name = name;
        this.email = email;
        this.isSetup = isSetup;
        this.accountOptions = accountOptions;
    }

    @Override
    public String toString() {
        return id + ',' + name + ',' + email + ',' + isSetup + ',' + accountOptions;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public Integer getIsSetup() {
        return isSetup;
    }

    public void setIsSetup(Integer isSetup) {
        this.isSetup = isSetup;
    }

    public Long getAccountOptions() {
        return accountOptions;
    }

    public void setAccountOptions(Long accountOptions) {
        this.accountOptions = accountOptions;
    }

    @Override
    public void write(PreparedStatement statement) throws SQLException {
        statement.setString(1, id);
        statement.setString(2, name);
        statement.setString(3, email);
        statement.setInt(4, isSetup);
        statement.setLong(5, accountOptions);
    }

    @Override
    public void readFields(ResultSet resultSet) throws SQLException {
        this.id = resultSet.getString(1);
        this.name = resultSet.getString(2);
        this.email = resultSet.getString(3);
        this.isSetup = resultSet.getInt(4);
        this.accountOptions = resultSet.getLong(5);
    }
}
